<?php
include_once __DIR__.'/../../vendor/autoload.php';  
if (strpos(strtolower(PHP_OS), 'win') === 0) {
    class_alias(\Windows\Worker::class,\Workerman\Worker::class);
    class_alias(\Windows\Events\Select::class,\Workerman\Events\Select::class);
}   



\Proc::fork(function(){

    //尝试监听 TCP
    $socket = \stream_socket_server('tcp://0.0.0.0:55555', $errno, $errstr) or exit; 
    //监听 TCP 成功后启动事件循环
    $event = Proc::startEventLoop();
    $event->add($socket, \Workerman\Events\EventInterface::EV_READ, function ($socket) { 
        \stream_socket_accept($socket, 0, $addr);

        $socket = \stream_socket_client('tcp://'.$addr, $errno, $errstr) or exit; 
        echo fread($socket,1);
        exit;

    });
});


sleep(1);
$socket = \stream_socket_client('tcp://127.0.0.1:55555', $errno, $errstr) or exit; 
fwrite($socket,'12345');